<template>
    <view class="flex flex-items-center">
        <!-- <view class="btn-wrap btn-cut" v-if="selected>min" @click="cut"></view> -->
        <view class="pl20 pr20 f30" v-if="selected>min">{{selected}}</view>
        <view class="btn-wrap btn-add" @click="add"></view>
    </view>
</template>

<script>
	export default {
        name:'productChange',
        props:{
            max:{
                type: Number,
                default: 100
            },
            min:{
                type: Number,
                default: 0
            },
            step:{
                type: Number,
                default: 1
            },
            selected:{
                type: Number,
                default: 0
            },
        },
		methods: {
            add(){
                if(this.selected<this.max){
                    const am = this.selected + this.step
                    const rest = am > this.max ? this.max : am
                    // this.$emit('update:selected', rest)
                    this.$emit('onChange', { rest, type: 'add' })
                }
            },
            cut(){
                if(this.selected>this.min){
                    const am = this.selected - this.step
                    const rest = am < this.min ? this.min : am
                    // this.$emit('update:selected', rest)
                    this.$emit('onChange', { rest, type: 'cut' })
                }
            }
		}
	}
</script>

<style lang="scss" scoped>
    @import '../base.scss';
    $btn-w-size: 60%;
    $btn-h-size: 4rpx;
    $btn-bg-color: #ffbd86;
    $btn-color: #212121;
    .btn-wrap{
        display: flex;
        width: 42rpx;
        height: 42rpx;
        background: transparent;
        border: 2rpx solid $btn-bg-color;
        border-radius: 15rpx;
        align-items: center;
        justify-content: center;
        position: relative;
        &::after{
            display: block;
            width: $btn-w-size;
            height: $btn-h-size;
            background-color: $btn-color;
            content: '';
            border-radius: 10rpx 10rpx;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
        &.btn-cut{
            &::after{
                background-color: $btn-color;
            }
        }
        &.btn-add{
            background-color: $btn-bg-color;
            &::before{
                display: block;
                height: $btn-w-size;
                width: $btn-h-size;
                background-color: $btn-color;
                content: '';
                border-radius: 10rpx 10rpx;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%,-50%);
            }
        }
    }
</style>
